<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/pages/common/header.jsp"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>First Challan</title>
		<style>
			@media print
			{
				table { page-break-after:auto }
  				tr    { page-break-inside:avoid; page-break-after:auto }
  				td    { page-break-inside:avoid; page-break-after:auto }
  				thead { display:table-header-group }
			}
		</style>
		
		<script>
			//Select all checkboxes
			function chooseAll() {
				var chk_arr = document.getElementsByName("chk");
				var chklength = chk_arr.length;
				for (count = 0; count < chklength; count++) {
					//if (chk_arr[count].checked == true)
						//chk_arr[count].checked = false;
					//else if (chk_arr[count].checked == false)
						chk_arr[count].checked = true;
				}
			}
		
			// Prepare array of IDs to be submitted
			function submitSelectedRecords() {
					
				var table = document.getElementById("excelInfo");
				var chk_arr = document.getElementsByName("chk");
				var chklength = chk_arr.length;
				var elemArr = [];
				var index = 0;
				for ( var count = 0; count < chklength; count++) {
					if (chk_arr[count].checked == true) {
						elemArr[index] = chk_arr[count].id;
						index++;
					}
				}
				
				var elem = document.getElementById("challan1Ids");
				elem.value = elemArr;
				
				
			}
			function createDate(){
				var dateInString = document.getElementById("dateInString").value;
				
				document.getElementById("datefrmFirstChallan").value=dateInString;
				
			}
		</script>
	</head>
	<body class="mainbody">
		<c:set var="tradersList" value="${requestScope.tradersList}" />
		<c:set var="date" value="${requestScope.date}" />
		<c:set var="seperator" value="," />
		<c:set var="grossWeightTotal" value="0" />
		<c:set var="netWeightTotal" value="0" />
		<div class="mainContainer">
			<section class="bodyContainer">
			<form id="billTableForm" action="${context}/challan2" method="post">
			<div id="selectTraders" class="">
				<div class="divclear billHideClass">
					<span class="loginlabel">Select Traders : </span> <span
						class="logininputFld"> <select id="showTraderMode"
						name="trader" class="loginSelectfld">
							<c:if test="${not empty fn:length(tradersList)}">
								<c:forEach var="traders" items="${tradersList}">
									<option value="${traders.companyId}${seperator}${traders.companyName}">${traders.companyName}</option>
								</c:forEach>
							</c:if>
					</select> </span>
				</div>
	
			</div>
					
			<div class="divclear">
				<span><h1 style="text-align: center; font-weight: bold; font-size: 22px;"><div id="showTraders"></div></h1> </span> 
			</div>
			<p class="spacerTopTen"></p>
			<div class="divclear">
				<h4 style="text-align: center; font-weight: bold; font-size:14px;">DETAILS TRANSPORTATION WEIGH-BRIDGE</h4>
			</div>
			
			<div class="clear">
				<fmt:formatDate var="dateInString" type="date" value="${date}" />
				<h4 style="text-align: left; font-weight: bold; font-size: 14px;">RA.BILL NO.: <input type="text" class="billproddLable" name="raBillNo" id="billNo" /></h4>
				<h4 style="text-align:left; font-weight: bold; font-size:14px;">Date: <input type="text" value="${dateInString}" class="billproddLable" name="dateInString" id="dateInString"/></h4>
			</div>
			<p class="hrlineBr"></p>
			<div id="firstChallan" class="">
	
				<div class="productDtls">
					<p class="spacerTopTen"></p>
					<div class="divclear">
						<span class="valia">VALIA MINES SIDE</span>	
						<span class="vastan">VASTAN SIDE</span>				
					</div>
					<div class="divclear autoTableWith">
						<table cellpadding="0" cellspacing="0" border="1px solid #333"
							class="display reportTable01" id="firstChallanTable"
							style="width: 1000px; border:1px solid #333; text-align: center; font-family: arial;">
							<thead>
								<!-- <tr>
									<th colspan="3"></th>
									<th colspan="5">VALIA MINES SIDE</th>
									<th colspan="6">VASTAN SIDE</th>
								</tr> -->
										
								<tr>
									<!-- <th><input type="checkbox" id="chkAll" name="chkAll"
										onclick="chooseAll();" />
									</th> -->
									<th>Sr.No.</th>
									<th>SLIP NO</th>
									<th>TRUCK NO</th>
									<th>SUB TRANSPORTER NAME</th>
									<th>IN W.B. NO.</th>
									
									<th>IN TIME</th>
									<th>IN DATE</th>
									<th>TARE WEIGHT</th>
									<th>GROSS WEIGHT</th>
									<th>NET WEIGHT</th>
									
									<th>INVOICE NO</th>
									<th>ROYALTY<br> PASS NO.</th>
									<th>GROSS WEIGHT</th>
									<th>TARE WEIGHT</th>
									
									<th>NET WEIGHT</th>
									<th>DUMP LOCATION</th>
	
								</tr>
								</thead>
							<tbody>
								<c:if test="${data ne null && not empty data}">
									<c:forEach var="record" items="${data}" varStatus="count">
										<c:set var="grossWeightTotal"
											value="${grossWeightTotal + record.vsGrossWeight}" />
										<c:set var="netWeightTotal"
											value="${netWeightTotal + record.vsNetWeight}" />
											<!-- <input type="checkbox" id="${record.masterId}" name="chk" checked="checked" hidden/> -->
										<tr>
											<td style="display: none"><input type="checkbox"
												id="${record.masterId}" name="chk" checked="checked"/>
											</td>
											<td>${count.index+1}</td>
											<td>${record.slipNo}</td>
											<td>${record.truckNo}</td>
											<td>${record.subTransporterName}</td>
											<td>${record.vmsInWbNo}</td>
											
											<td>${record.vmsInDate}</td>
											<td>${record.vmsInTime}</td>
											<td>${record.vmsTareWeight}</td>
											<td>${record.vmsGrossWeight}</td>
											<td>${record.vmsTotalWeight}</td>

											<td>${record.invoiceNo}</td>
											<td>${record.royalityPassNo}</td>

											<td>${record.vsGrossWeight}</td>
											<td>${record.vsTareWeight}</td>
											<td>${record.vsNetWeight}</td>
											<td>${record.dumpLocation}</td>

										</tr>
									</c:forEach>
								</c:if>
								<tr>
									<td colspan="11"></td>
									<td>Total Gross:</td>
									<td><fmt:formatNumber pattern="0.000" value="${grossWeightTotal}"/></td>
									<td>Total NetWeight:</td>
									<td><fmt:formatNumber pattern="0.000" value="${netWeightTotal}"/></td>
									<td></td>
								</tr>
							</tbody>
						</table>
					</div>
					<p class="spacerTopTen"></p>
					<p class="spacerTopTen"></p>
				</div>
				<input type="hidden" name="challan1Ids" id="challan1Ids" />
				<input type="hidden" name="ACTION" value="SECC">
				<input type="hidden" name="grossWeightTotal" value="${grossWeightTotal}">
				<input type="hidden" name="netWeightTotal" value="${netWeightTotal}">
				<input type="hidden" id="datefrmFirstChallan" name="datefrmFirstChallan" value="${dateInString}">
				<div id="hiddenTraders"></div>
				<div id="buttonShow">
					<div id="buttonsHide" class="divclear">
						<span class="buttonSiyora button80">
						<input type="submit" value="Submit" onclick="submitSelectedRecords();"/></span> <span
							class="buttonSiyora button80"
							onclick="printFirstChallan();AfterPrint()"><a>Print</a> </span>
							<span class="buttonSiyora button80"><a href="${context}/pages/jsp/welcome.jsp" >Home </a> </span>
					</div>
				</div>
			</div>
			</form>
	
			</section>
		</div>
	
	</body>
</html>